//
//  GMExerciseNotesVC.m
//  Teecloud
//
//  Created by 小熊 on 2018/11/27.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "GMExerciseNotesVC.h"
#import "GMExerciseNotesModel.h"
#import "GMExamModel.h"
#import "GMExerciseNotesCell.h"
#import "GMAnalysisVC.h"
#import "GMSubjectsModel.h"
@interface GMExerciseNotesVC ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *titleName;
@property (weak, nonatomic) IBOutlet UILabel *lableq;
@property (weak, nonatomic) IBOutlet UILabel *lablew;
@property (weak, nonatomic) IBOutlet UILabel *lablee;
@property (weak, nonatomic) IBOutlet UITableView *tabView;


@property (nonatomic, strong) NSMutableArray *dataArr;
@end

@implementation GMExerciseNotesVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"随堂练习本";
    [self getGMExerciseNotesData];
    [self.tabView registerNib:[UINib nibWithNibName:@"GMExerciseNotesCell" bundle:nil] forCellReuseIdentifier:@"GMExerciseNotesCell"];
}
-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [[NSMutableArray alloc] init];
    }
    return _dataArr;
}
-(void)getGMExerciseNotesData{
    NSDictionary *dict= @{@"from":FROM_IOS,
                          @"busiOrgId":[XGMArchiverTools cacheForKey:BUSIORGID],
                          @"loginFinger":[XGMArchiverTools cacheForKey:USER_identifierNumber],
                          @"userId":[XGMArchiverTools cacheForKey:USER_UserId],
                          @"studyExamId":self.studyExamId,
                          @"pageIndex":@(0),
                          @"pageSize":@(10)
                          };
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=GetExmInStudyList&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                GMExerciseNotesModel *model = [GMExerciseNotesModel mj_objectWithKeyValues:[responseObject objectForKey:RESULT_NAME_Data]];
                [self uploadDataWithModel:model];
                [self.dataArr removeAllObjects];
                [self.dataArr addObjectsFromArray:model.AnserCards];
                [self.tabView reloadData];
            }else{
                 [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:self.view];
            }
        }else{
            [MBProgressHUD showErrorOrSuc:@"网络错误" toView:self.view];
        }
    }];
}
- (void)uploadDataWithModel:(GMExerciseNotesModel *)model{
    self.titleName.text = [NSString stringWithFormat:@"%@(%@)",model.Title,model.ResName];
    self.lableq.text = model.CorrectRate;
    self.lablew.text = model.UseTime;
    self.lablee.text = model.AverageTime;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GMExerciseNotesCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GMExerciseNotesCell" forIndexPath:indexPath];
    GMExamModel *model = self.dataArr[indexPath.row];
    cell.model = model;
    cell.itemBlock = ^(NSInteger index) {
        GMAnalysisVC *analy = [[GMAnalysisVC alloc] init];
        analy.baseModel = model;
        analy.index = index+1;
        [self.navigationController pushViewController:analy animated:YES];
    };
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    GMExamModel *model = self.dataArr[indexPath.row];
    return model.cellHight;
}

@end
